package com.vaeke.app.sina.index;

import java.util.ArrayList;
import java.util.List;


import weibo4j.Status;
import weibo4j.Weibo;
import weibo4j.WeiboException;

public class GetFriendsTimeline {
	public List<Status> getFriendsTimeline(boolean isOauth, String[] args) {
		Weibo weibo = getWeibo(isOauth, args);
		List<Status> statuses = new ArrayList<Status>();
		try {
			statuses = weibo.getFriendsTimeline();
		} catch (WeiboException e) {
			e.printStackTrace();
		}
		return statuses;
	}

	private static Weibo getWeibo(boolean isOauth, String[] args) {
		System.setProperty("weibo4j.oauth.consumerKey", Weibo.CONSUMER_KEY);
		System.setProperty("weibo4j.oauth.consumerSecret",
				Weibo.CONSUMER_SECRET);

		Weibo weibo = new Weibo();
		if (isOauth) {//oauth check 1.token 2. token secret
			weibo.setToken(args[0], args[1]);
		} else {//login
			weibo.setUserId(args[0]);//id
			weibo.setPassword(args[1]);//pwd
		}
		return weibo;
	}
}
